<!--
 * @Author: ZhaoZhiqi
 * @Date: 2022-08-18 10:03:37
 * @LastEditors: ZhaoZhiqi
 * @LastEditTime: 2022-08-18 10:13:31
 * @Description: 自定义按钮
 *
 * 属性
 * width      按钮宽度(默认 82)         Number
 * icon       图标地址(默认 "")         String
 * disabled   禁用状态(默认 false)      Boolean
 * loading    加载状态(默认 false)      Boolean
 * bgColor    背景颜色(默认 "#f5f6f9")  String
 * color      字体颜色(默认 "#2b2b2b")  String
 * openType   开放类型(默认 "")         String
 *
 * 插槽
 * slot 内容
 * 
 * 事件
 * @click
 * @FilePath: \tuanfeng-mini\src\components\Btn.vue
-->
<template>
  <button
    class="button"
    :style="{
      width: width + 'px',
      backgroundColor: bgColor,
    }"
    :open-type="openType"
    @click="click"
  >
    <!-- 正常状态 -->
    <template v-if="!loading">
      <!-- 按钮icon -->
      <div
        v-if="icon"
        class="icon"
        :style="{ backgroundImage: `url(${icon})` }"
      ></div>

      <!-- 按钮内容 -->
      <div class="text" :style="{ color: disabled ? '#b7b7b7' : color }">
        <slot>点击</slot>
      </div>
    </template>

    <!-- 加载状态 -->
    <u-loading v-else mode="circle"></u-loading>
  </button>
</template>

<script>
import Vue from "vue";
const app = getApp();

export default Vue.extend({
  props: {
    width: {
      type: Number,
      default: 82,
    },
    icon: {
      type: String,
      default: "",
    },
    disabled: {
      type: Boolean,
      default: false,
    },
    loading: {
      type: Boolean,
      default: false,
    },
    bgColor: {
      type: String,
      default: "#f5f6f9",
    },
    color: {
      type: String,
      default: "#2b2b2b",
    },
    openType: {
      type: String,
      default: "",
    },
  },
  data() {
    return {};
  },
  methods: {
    click() {
      this.$emit("click");
    },
  },
});
</script>

<style lang="scss" scoped>
@import "../assets/scss/common.scss";

.button {
  height: 80rpx;
  border-radius: 40rpx;
  background-color: #f5f6f9;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0;
  &::after {
    border: none;
  }
  .icon {
    width: 34rpx;
    height: 34rpx;
    margin-right: 8rpx;
    background-repeat: no-repeat;
    background-size: contain;
    background-position: center;
  }
  .text {
    font-size: 32rpx;
    line-height: 80rpx;
    font-weight: bold;
  }
}
</style>